﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using RoadTeam.SysInterface;
using RoadTeam.Model;
using RoadTeam.Enums;
using RoadTeam.Pub;

namespace RoadTeam.BLL
{
    public class SmOrganBll
    {
        private static object o = new object();
        public int ReflashData()
        {
            DataTable dt_Organ = GetEmptyTable();
            DataRow dr_Organ;
            lock (o)
            {
                DataTable dt = FactoryClass.CreateSmOrgan().GetOrganTable();


                foreach (DataRow dr in dt.Rows)
                {
                    dr[3] = CreateIdentifier.GetIdentifier();
                    dr_Organ = dt_Organ.NewRow();
                    dr_Organ["OrganIdentifier"] = dr[3];
                    dr_Organ["OrganCode"] = dr[1];
                    dr_Organ["OrganName"] = dr[2];
                    dt_Organ.Rows.Add(dr_Organ);
                }
                FactoryClass.CreateSmOrgan().UpdateOrganInfo(dt);
            }
            SmOrgan.InsertDatatable(dt_Organ, GlobalConfig.ConnectionString);
            return dt_Organ.Rows.Count;
        }

        public DataTable GetEmptyTable()
        {
            SqlWhere where = new SqlWhere();
            where.Info = new Model.SmOrgan() { OrganIdentifier = "-1" };
            where.SelectColumn = @"   OrganIdentifier,OrganCode,OrganName ";
            return SmOrgan.Select(where, GlobalConfig.ConnectionString);
        }



    }
}
